package com.findMoneyGame.pages.game.controllers {
	import flash.display.Bitmap;
	import flash.events.Event;

	import com.findMoneyGame.pages.game.GameLevelPage;
	import com.findMoneyGame.pages.game.GameImage;
	import com.findMoneyGame.pages.game.controllers.Controller;
	import com.findMoneyGame.tools.ImageAdjuster;

	public class GameImageController extends Controller {
		public function GameImageController (gameLevelPage : GameLevelPage) {
			super(gameLevelPage);
			var bitmap = new Bitmap(ImageAdjuster.adjust(gameLevel.image, _gameLevelPage.imageWidth, _gameLevelPage.imageHeight));
			gameImage = new GameImage(user, gameLevel, bitmap);
			gameImage.addEventListener(GameImage.MONEY_FOUNDED, function () { _gameLevelPage.levelComplete(); });
			gameImage.addEventListener(GameImage.TRYING_FAILED, tryingFailed);
			_gameLevelPage.addChildAt(gameImage, 1);
			gameImage.x = 10;
			gameImage.y = 10;
		}

		private function tryingFailed (e : Event) {
			if (gameLevel.data.reward > 0) {
				gameLevel.data.reward -= gameLevel.data.failingPrice
			}
		}
	}
}